package org.example.modules.user.controller;

import com.alibaba.fastjson2.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.example.modules.user.common.Commsult;
import org.example.modules.user.entry.SideJobMain;
import org.example.modules.user.entry.vo.JobFeedBackVo;
import org.example.modules.user.entry.vo.OrderRankVo;
import org.example.modules.user.entry.vo.SideJobMainVo;
import org.example.modules.user.service.SideJobMainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description SideJobMainController
 * @Author xiaotian
 * @Date 2025-04-17
 */
@RestController
@RequestMapping("/wxApi/sideJob")
@Slf4j
public class SideJobMainController {
    @Autowired
    private SideJobMainService sideJobMainService;

    @PostMapping("/save")
    public Commsult<List<SideJobMainVo>> saveSideJob(@RequestBody JSONObject data){
        Integer flag =sideJobMainService.saveSideJob(data);
        if(flag==0){
            return Commsult.fail("余额不足，请先充值");
        }
        return Commsult.success(sideJobMainService.getAllSideJob());
    }


    @GetMapping("/getAllSideJob")
    public Commsult<List<SideJobMainVo>> getAllSideJob(){

        return Commsult.success(sideJobMainService.getAllSideJob());
    }
    @PostMapping("/getJob")
    public Commsult<List<SideJobMainVo>> getJob(@RequestBody JSONObject data){
        return Commsult.success(sideJobMainService.getSideJob(data));
    }

    @PostMapping("/getJobDetails")
    public Commsult<SideJobMainVo> getJobDetails(@RequestBody JSONObject data){
        return Commsult.success(sideJobMainService.getSideJobDetails(data));
    }

    @PostMapping("/acceptJob")
    public Commsult accpetJob(@RequestBody JSONObject data) throws Exception {

        return sideJobMainService.accpetJob(data);
    }
    @GetMapping("/orderRank")
    public Commsult<List<OrderRankVo>> getOrderRank(){
        return Commsult.success(sideJobMainService.getOrderRank());
    }

    @GetMapping("/getJobFeedback")
    public Commsult<List<JobFeedBackVo>> getJobFeedback(){
        return Commsult.success(sideJobMainService.getJobFeedback());
    }

    @GetMapping("/getById/{orderId}")
    public Commsult<SideJobMain> getJobDetailsById(@PathVariable Integer orderId){
        return Commsult.success(sideJobMainService.getJobDetailsById(orderId));
    }

}
